// 初始化 Squelize,与本地数据库相连接
const dbConfig = require('../config/db.config')

const Sequelize = require('sequelize')

const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
	host: dbConfig.HOST,
	port: dbConfig.PORT,
	dialect: dbConfig.dialect,
	timezone: '+08:00',
	pool: {
		max: dbConfig.pool.max,
		min: dbConfig.pool.min,
		acquire: dbConfig.pool.acquire,
		idle: dbConfig.pool.idle,
	},
	define: {
		underscored: true,
	},
})

const db = {}
db.Sequelize = Sequelize
db.sequelize = sequelize
db.accounts = require('./accounts.model')(sequelize, Sequelize)
db.medicine = require('./medicine.model')(sequelize, Sequelize)
db.order = require('./order.model')(sequelize, Sequelize)
db.pharmacy = require('./pharmacy.model')(sequelize, Sequelize)
db.rxeq = require('./rxreq.model')(sequelize, Sequelize)
db.stock = require('./stock.model')(sequelize, Sequelize)
db.recAddress = require('./recAddress.model')(sequelize, Sequelize)

module.exports = db
